//package com.daocao.hua.fragment;
//
//import android.animation.Animator;
//import android.animation.ObjectAnimator;
//import android.content.Intent;
//import android.os.Bundle;
//import android.support.v4.widget.NestedScrollView;
//import android.support.v4.widget.SwipeRefreshLayout;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.view.ViewTreeObserver;
//import android.widget.FrameLayout;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//
//import com.allen.library.SuperButton;
//import com.bumptech.glide.Glide;
//import com.daocao.hua.R;
//import com.daocao.hua.activity.InviteRecordActivity;
//import com.daocao.hua.activity.MyPrizeActivity;
//import com.daocao.hua.activity.MyQrCodeActivity;
//import com.daocao.hua.activity.WebViewActivity;
//import com.daocao.hua.adapter.MainHomeOrderAdapter;
//import com.daocao.hua.adapter.MainHomePrizeAdapter;
//import com.daocao.hua.api.Api;
//import com.daocao.hua.api.bean.PrizeIndexBean;
//import com.daocao.hua.constant.Const;
//import com.daocao.hua.constant.UserGlobal;
//import com.daocao.hua.model.PrizeIndexModel;
//import com.daocao.hua.util.RxLifeUtil;
//import com.daocao.hua.util.Util;
//import com.daocao.hua.view.NoticeView;
//import com.daocao.hua.view.V19RelativeLayout;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import butterknife.BindView;
//import butterknife.ButterKnife;
//import butterknife.OnClick;
//import butterknife.Unbinder;
//import de.hdodenhof.circleimageview.CircleImageView;
//import pl.droidsonroids.gif.GifDrawable;
//import pl.droidsonroids.gif.GifImageView;
//
///**
// * Created by xsooy-pc on 18-7-24.
// */
//
//public class MainHomePrizeFragment extends BaseFragment {
//
//
//    @BindView(R.id.img_icon)
//    CircleImageView imgIcon;
//    @BindView(R.id.txt_user)
//    TextView txtUser;
//    @BindView(R.id.btn_my_qrcode)
//    LinearLayout btnMyQrcode;
//    @BindView(R.id.layout_title)
//    V19RelativeLayout layoutTitle;
//    @BindView(R.id.view_bottom)
//    View viewBottom;
//    @BindView(R.id.noticeText)
//    NoticeView noticeText;
//    @BindView(R.id.btn_rule)
//    SuperButton btnRule;
//    @BindView(R.id.img_icon_one)
//    ImageView imgIconOne;
//    @BindView(R.id.txt_user_one)
//    TextView txtUserOne;
//    @BindView(R.id.layout_float_one)
//    RelativeLayout layoutFloatOne;
//    @BindView(R.id.img_icon_two)
//    ImageView imgIconTwo;
//    @BindView(R.id.txt_user_two)
//    TextView txtUserTwo;
//    @BindView(R.id.layout_float_two)
//    RelativeLayout layoutFloatTwo;
//    @BindView(R.id.img_icon_gif)
//    GifImageView imgIconGif;
//    @BindView(R.id.txt_invite_num)
//    TextView txtInviteNum;
//    @BindView(R.id.btn_invite_num)
//    TextView btnInviteNum;
//    @BindView(R.id.txt_money_num)
//    TextView txtMoneyNum;
//    @BindView(R.id.btn_money_num)
//    TextView btnMoneyNum;
//    @BindView(R.id.txt_thing_num)
//    TextView txtThingNum;
//    @BindView(R.id.btn_thing_num)
//    TextView btnThingNum;
//    @BindView(R.id.list_one)
//    RecyclerView listOne;
//    @BindView(R.id.img_level_two)
//    ImageView imgLevelTwo;
//    @BindView(R.id.img_level_one)
//    ImageView imgLevelOne;
//    @BindView(R.id.txt_level_two)
//    TextView txtLevelTwo;
//    @BindView(R.id.img_level_three)
//    ImageView imgLevelThree;
//    @BindView(R.id.txt_level_three)
//    TextView txtLevelThree;
//    @BindView(R.id.layout_money_title)
//    LinearLayout layoutMoneyTitle;
//    @BindView(R.id.list_two)
//    RecyclerView listTwo;
//    @BindView(R.id.img_level_two_sec)
//    ImageView imgLevelTwoSec;
//    @BindView(R.id.img_level_one_sec)
//    ImageView imgLevelOneSec;
//    @BindView(R.id.txt_level_two_sec)
//    TextView txtLevelTwoSec;
//    @BindView(R.id.img_level_three_sec)
//    ImageView imgLevelThreeSec;
//    @BindView(R.id.txt_level_three_sec)
//    TextView txtLevelThreeSec;
//    @BindView(R.id.layout_money_title_sec)
//    LinearLayout layoutMoneyTitleSec;
//    @BindView(R.id.list_three)
//    RecyclerView listThree;
//
//    Unbinder unbinder;
//    @BindView(R.id.view_top)
//    View viewTop;
//    @BindView(R.id.btn_close)
//    ImageView btnClose;
//    @BindView(R.id.layout_notice)
//    LinearLayout layoutNotice;
//    @BindView(R.id.img_total_bg)
//    ImageView imgTotalBg;
//    @BindView(R.id.img_content_one)
//    ImageView imgContentOne;
//    //    @BindView(R.id.img_content_two)
////    ImageView imgContentTwo;
////    @BindView(R.id.img_content_three)
////    ImageView imgContentThree;
//    @BindView(R.id.fl_notice)
//    FrameLayout flNotice;
//    @BindView(R.id.txt_level_one)
//    TextView txtLevelOne;
//    @BindView(R.id.txt_level_one_sec)
//    TextView txtLevelOneSec;
//    @BindView(R.id.refresh)
//    SwipeRefreshLayout refresh;
//    @BindView(R.id.scrollView)
//    NestedScrollView scrollView;
//    private GifDrawable gifDrawable;
//    //    private AnimationSet animation;
//    private ObjectAnimator animation;
//    private ObjectAnimator animation1;
//    private int num;
//    private MainHomeOrderAdapter adapterReward;
//    private MainHomePrizeAdapter adapterPrize;
//    private List<PrizeIndexModel.DataBean.InviteListBean> invite_list;
//    private WeekListAdapter weekListAdapter;
//    private String week_num = "";
//
//    @Override
//    protected int setLayoutId() {
//        return R.layout.fragment_main_home_prize;
//    }
//
//    @Override
//    protected void initView() {
//        scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
//            @Override
//            public void onScrollChanged() {
//                refresh.setEnabled(scrollView.getScrollY() == 0);
//            }
//        });
//        refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
//            @Override
//            public void onRefresh() {
//                getPrizeIndex(week_num);
//            }
//        });
//        adapterReward = new MainHomeOrderAdapter(getContext());
//        listTwo.setAdapter(adapterReward);
//
//        adapterPrize = new MainHomePrizeAdapter(getContext());
//        listThree.setAdapter(adapterPrize);
//
//        listOne.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
//        weekListAdapter = new WeekListAdapter(getContext());
//        weekListAdapter.setOnChooseListener(new WeekListAdapter.OnChooseListener() {
//            @Override
//            public void onClick(String content) {
//                week_num = content;
//                getPrizeIndex(content);
//            }
//        });
//        listOne.setAdapter(weekListAdapter);
//
//        imgIconGif.setImageResource(R.mipmap.gif_invite);
//        gifDrawable = (GifDrawable) imgIconGif.getDrawable();
//        Glide.with(this).load(R.mipmap.img_main_invite_bg).into(imgTotalBg);
//        Glide.with(this).load(R.mipmap.img_main_my_reward).into(imgContentOne);
////        Glide.with(this).load(R.mipmap.img_main_money_bg).into(imgContentTwo);
////        Glide.with(this).load(R.mipmap.img_main_my_thing).into(imgContentThree);
//        initAnimation();
//
//    }
//
//    private void initAnimation() {
//        animation = ObjectAnimator.ofFloat(layoutFloatOne, "alpha", 0f, 0.5f, 1f, 1f, 0f);
//        animation.setRepeatCount(-1);
//        animation.setDuration(5000);
//        animation.addListener(new Animator.AnimatorListener() {
//            @Override
//            public void onAnimationStart(Animator animation) {
//                txtUserOne.setText(invite_list.get(0).mobile + invite_list.get(0).name + "\n" + invite_list.get(0).text);
//            }
//
//            @Override
//            public void onAnimationEnd(Animator animation) {
//
//            }
//
//            @Override
//            public void onAnimationCancel(Animator animation) {
//
//            }
//
//            @Override
//            public void onAnimationRepeat(Animator animation) {
//                int poi = num++ % invite_list.size();
//                txtUserOne.setText(invite_list.get(poi).mobile + invite_list.get(poi).name + "\n" + invite_list.get(poi).text);
//
//            }
//        });
//
//        animation1 = ObjectAnimator.ofFloat(layoutFloatTwo, "alpha", 0f, 0.5f, 1f, 1f, 0f);
//        animation1.setRepeatCount(-1);
//        animation1.setDuration(5000);
//        animation1.addListener(new Animator.AnimatorListener() {
//            @Override
//            public void onAnimationStart(Animator animation) {
//                int poi = num++ % invite_list.size();
//                txtUserTwo.setText(invite_list.get(poi).mobile + invite_list.get(poi).name + "\n" + invite_list.get(poi).text);
//            }
//
//            @Override
//            public void onAnimationEnd(Animator animation) {
//
//            }
//
//            @Override
//            public void onAnimationCancel(Animator animation) {
//
//            }
//
//            @Override
//            public void onAnimationRepeat(Animator animation) {
//                int secpoi = num++ % invite_list.size();
//                txtUserTwo.setText(invite_list.get(secpoi).mobile + invite_list.get(secpoi).name + "\n" + invite_list.get(secpoi).text);
//                if (num >= invite_list.size()) {
//                    num = 0;
//                }
//            }
//        });
//    }
//
//
//    public void getPrizeIndex(String week_num) {
//        refresh.setRefreshing(true);
//        PrizeIndexBean bean = new PrizeIndexBean();
//        bean.week_num = week_num;
//        Api.api_service.getPrizeIndex(bean).compose(RxLifeUtil.checkOn(getContext())).
//                doFinally(() -> {
//                    try {
//                        refresh.setRefreshing(false);
//                    } catch (NullPointerException e) {
//
//                    }
//
//                }).
//                subscribe(result -> {
//                    PrizeIndexModel.DataBean.StatisticsBean statisticsData = result.data.statistics;
//                    txtInviteNum.setText(statisticsData.register);
//                    txtMoneyNum.setText(statisticsData.total);
//                    txtThingNum.setText(statisticsData.goods_num);
////                    公告栏
//                    noticeText.setList(result.data.prize_notice);
//
////                    邀请列表
//                    invite_list = result.data.invite_list;
////                    开启动画
//                    if (invite_list != null && invite_list.size() != 0) {
//                        if (animation.isRunning()) {
//                            animation.cancel();
//                        }
//                        if (animation1.isRunning()) {
//                            animation1.cancel();
//                        }
//                        animation.start();
//                        txtUser.postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//                                animation1.start();
//                            }
//                        }, 3000);
//                    }
//
//                    weekListAdapter.update(result.data.week_list);
//
////                    ======================================================================
////                    奖金大神磅
//                    List<PrizeIndexModel.DataBean.RewardListBean> reward_list = result.data.reward_list;
//                    if (reward_list != null && reward_list.size() != 0) {
////                      奖金大神磅  排版前三名
//                        if (reward_list.size() == 1) {
//                            imgLevelOne.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(reward_list.get(0).header).error(R.mipmap.img_invite_level_one).into(imgLevelOne);
//                            txtLevelOne.setText(reward_list.get(0).real_name + "\n￥" + reward_list.get(0).total_reward);
//                            imgLevelTwo.setVisibility(View.INVISIBLE);
//                            txtLevelTwo.setText("");
//                            imgLevelThree.setVisibility(View.INVISIBLE);
//                            txtLevelThree.setText("");
//                            adapterReward.update(new ArrayList<>());
//                        } else if (reward_list.size() == 2) {
//                            imgLevelOne.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(reward_list.get(0).header).error(R.mipmap.img_invite_level_one).into(imgLevelOne);
//                            txtLevelOne.setText(reward_list.get(0).real_name + "\n￥" + reward_list.get(0).total_reward);
//                            imgLevelTwo.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(reward_list.get(1).header).error(R.mipmap.img_invite_level_two).into(imgLevelTwo);
//                            txtLevelTwo.setText(reward_list.get(1).real_name + "\n￥" + reward_list.get(1).total_reward);
//                            imgLevelThree.setVisibility(View.INVISIBLE);
//                            txtLevelThree.setText("");
//                            adapterReward.update(new ArrayList<>());
//                        } else {
//                            imgLevelOne.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(reward_list.get(0).header).error(R.mipmap.img_invite_level_one).into(imgLevelOne);
//                            txtLevelOne.setText(reward_list.get(0).real_name + "\n￥" + reward_list.get(0).total_reward);
//                            imgLevelTwo.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(reward_list.get(1).header).error(R.mipmap.img_invite_level_two).into(imgLevelTwo);
//                            txtLevelTwo.setText(reward_list.get(1).real_name + "\n￥" + reward_list.get(1).total_reward);
//                            imgLevelThree.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(reward_list.get(2).header).error(R.mipmap.img_invite_level_three).into(imgLevelThree);
//                            txtLevelThree.setText(reward_list.get(2).real_name + "\n￥" + reward_list.get(2).total_reward);
//                            if (reward_list.size() > 3) {
//                                reward_list.remove(0);
//                                reward_list.remove(0);
//                                reward_list.remove(0);
//                                adapterReward.update(reward_list);
//                            }else {
//                                adapterReward.update(new ArrayList<>());
//                            }
//                        }
//                    } else {
//                        imgLevelOne.setVisibility(View.INVISIBLE);
//                        imgLevelTwo.setVisibility(View.INVISIBLE);
//                        imgLevelThree.setVisibility(View.INVISIBLE);
//                        txtLevelOne.setText("");
//                        txtLevelTwo.setText("");
//                        txtLevelThree.setText("");
//                        adapterReward.update(new ArrayList<>());
//                    }
////                    ======================================================================
//
//
////                    ======================================================================
////                        奖品大神磅
//                    List<PrizeIndexModel.DataBean.PrizeListBean> prize_list = result.data.prize_list;
//                    if (prize_list != null && prize_list.size() != 0) {
////                      奖品大神磅  排版前三名
//                        if (prize_list.size() == 1) {
//                            imgLevelOneSec.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(prize_list.get(0).header).error(R.mipmap.img_invite_level_one).into(imgLevelOneSec);
//                            txtLevelOneSec.setText(prize_list.get(0).real_name + "\n" + prize_list.get(0).goods);
//                            imgLevelTwoSec.setVisibility(View.INVISIBLE);
//                            txtLevelTwoSec.setText("");
//                            imgLevelThreeSec.setVisibility(View.INVISIBLE);
//                            txtLevelThreeSec.setText("");
//                        } else if (prize_list.size() == 2) {
//                            imgLevelOneSec.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(prize_list.get(0).header).error(R.mipmap.img_invite_level_one).into(imgLevelOneSec);
//                            txtLevelOneSec.setText(prize_list.get(0).real_name + "\n" + prize_list.get(0).goods);
//                            imgLevelTwoSec.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(prize_list.get(1).header).error(R.mipmap.img_invite_level_two).into(imgLevelTwoSec);
//                            txtLevelTwoSec.setText(prize_list.get(1).real_name + "\n" + prize_list.get(1).goods);
//                            imgLevelThreeSec.setVisibility(View.INVISIBLE);
//                            txtLevelThreeSec.setText("");
//                        } else {
//                            imgLevelOneSec.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(prize_list.get(0).header).error(R.mipmap.img_invite_level_one).into(imgLevelOneSec);
//                            txtLevelOneSec.setText(prize_list.get(0).real_name + "\n" + prize_list.get(0).goods);
//                            imgLevelTwoSec.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(prize_list.get(1).header).error(R.mipmap.img_invite_level_two).into(imgLevelTwoSec);
//                            txtLevelTwoSec.setText(prize_list.get(1).real_name + "\n" + prize_list.get(1).goods);
//                            imgLevelThreeSec.setVisibility(View.VISIBLE);
////                            Glide.with(getContext()).load(prize_list.get(2).header).error(R.mipmap.img_invite_level_three).into(imgLevelThreeSec);
//                            txtLevelThreeSec.setText(prize_list.get(2).real_name + "\n" + prize_list.get(2).goods);
//                        }
//                        adapterPrize.update(prize_list);
//                    } else {
//                        imgLevelOneSec.setVisibility(View.INVISIBLE);
//                        imgLevelTwoSec.setVisibility(View.INVISIBLE);
//                        imgLevelThreeSec.setVisibility(View.INVISIBLE);
//                        txtLevelOneSec.setText("");
//                        txtLevelTwoSec.setText("");
//                        txtLevelThreeSec.setText("");
//                        adapterPrize.update(prize_list);
//                    }
//
//                    //                    ======================================================================
//
//                });
//    }
//
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
//            savedInstanceState) {
//        // TODO: inflate a fragment view
//        View rootView = super.onCreateView(inflater, container, savedInstanceState);
//        unbinder = ButterKnife.bind(this, rootView);
//        return rootView;
//    }
//
//    @Override
//    public void onDestroyView() {
//        super.onDestroyView();
//    }
//
//    @Override
//    public void onResume() {
//        super.onResume();
//
//        if (UserGlobal.checkLogin()) {
//            getPrizeIndex(week_num);
////            int sex = UserGlobal.getSex();
////            if (sex == 0) {
////                Glide.with(getActivity()).load(UserGlobal.getHeader()).dontAnimate().placeholder(R.mipmap.img_main_prize_icon).error(R.mipmap.img_main_prize_icon).into(imgIcon);
////            } else {
////                Glide.with(getActivity()).load(UserGlobal.getHeader()).dontAnimate().placeholder(R.mipmap.img_my_boy).error(R.mipmap.img_my_boy).into(imgIcon);
////            }
//            Glide.with(getActivity()).load(UserGlobal.getHeader()).dontAnimate().placeholder(R.mipmap.img_main_prize_icon).error(R.mipmap.img_main_prize_icon).into(imgIcon);
//            txtUser.setText(UserGlobal.getUserName());
//        }
//
//        gifDrawable.start();
//        if (invite_list != null && invite_list.size() != 0) {
//            animation.start();
//            txtUser.postDelayed(new Runnable() {
//                @Override
//                public void run() {
//                    animation1.start();
//                }
//            }, 3000);
//        }
//
//    }
//
//    @Override
//    public void onPause() {
//        super.onPause();
//        gifDrawable.pause();
//        animation.cancel();
//        animation1.cancel();
//    }
//
//    @OnClick({R.id.btn_close, R.id.btn_my_qrcode, R.id.btn_rule, R.id.btn_invite_num, R.id.btn_money_num, R.id.btn_thing_num})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.btn_close:
//                flNotice.setVisibility(View.GONE);
//                break;
//            case R.id.btn_my_qrcode:
//                if (Util.checkLogin(getActivity()))
//                    Util.startActivity(getContext(), MyQrCodeActivity.class);
//                break;
//            case R.id.btn_rule:
//                Intent intent = new Intent(getContext(), WebViewActivity.class);
//                intent.putExtra("title", "活动规则");
//                intent.putExtra("url", Const.ACT_RULES);
//                startActivity(intent);
//                getActivity().overridePendingTransition(R.anim.right_enter, R.anim.left_out);
//                break;
//            case R.id.btn_invite_num:
//                if (Util.checkLogin(getActivity()))
//                    Util.startActivity(getContext(), InviteRecordActivity.class);
//                break;
//            case R.id.btn_money_num:
//                if (Util.checkLogin(getActivity()))
//                    Util.startActivity(getContext(), InviteRecordActivity.class);
//                break;
//            case R.id.btn_thing_num:
//                if (Util.checkLogin(getActivity()))
//                    Util.startActivity(getContext(), MyPrizeActivity.class);
//                break;
//        }
//    }
//
//
//}
